package org.testis.webautomationmodule.ui.objects;

import org.testis.logging.AtofLogLevel;
import org.testis.webautomationmodule.ui.UIBehaviorDecorator;


public class UIPromptAnswer extends UIBehaviorDecorator
{

    private String m_valToAnswer;


    public UIPromptAnswer(String valToAnswer)
    {
        setValToAnswer(valToAnswer);
    }


    /**
     * 
     * @return
     */
    @Override
    protected boolean setBehavior()
    {
        String hasPrompts = getWebAutomationImpl().getEval(
            "selenium.browserbot.hasPrompts();");
        if (hasPrompts.equals("true")) {
            getWebAutomationImpl().answerOnNextPrompt(getValToAnswer());
            String prompText = getWebAutomationImpl().getPrompt();
            putLog(" Confirming prompt (" + prompText + ") message with value " +
                   getValToAnswer());
            return true;
        }
        else {
            putLog(" Expected prompt  not found",AtofLogLevel.ERROR);
            return false;
        }
    }
    private String getValToAnswer()
    {
        return m_valToAnswer;
    }


    private void setValToAnswer(String valToAnswer)
    {
        this.m_valToAnswer = valToAnswer;
    }
}
